package com.kaifamiao.array;

import java.util.Arrays;

public class BubbleSortTest {

	public static void main(String[] args) {
		
		int[] array = { 2 , 1 , 6 , 9 , 0 , -1 , 99 , -10 };
		// array.length = 20 ; // The final field array.length cannot be assigned
		
		for( int i = 0 , m = array.length - 1 ; i < m ; i++ ) {
			for( int j = 0 , n = m - i ; j < n ; j++ ) {
				// 若相邻的两个元素中前一个比后一个大
				if( array[ j ] > array[ j + 1 ] ) {
					array[ j ] ^= array[ j + 1 ];
					array[ j + 1 ] ^= array[ j ];
					array[ j ] ^= array[ j + 1 ];
				}
			}
		}
		
		System.out.println( Arrays.toString( array ) );

	}

}
